package com.cbwl.eoas.cms.web.controller.eoas;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cbwl.eoas.cms.api.eoas.IAppOptionFeedbackService;
import com.cbwl.eoas.cms.api.sysconfig.IDictDetailService;
import com.cbwl.eoas.cms.model.eoas.AppOptionFeedbackDTO;
import com.cbwl.eoas.cms.model.sysconfig.DictDetailDTO;
import com.cbwl.eoas.common.framework.exception.CustomException;
import com.cbwl.eoas.common.framework.session.SessionManager;
import com.cbwl.eoas.common.framework.vo.PageRequest;
import com.cbwl.eoas.common.util.constain.DicDetailConstant;
import com.cbwl.eoas.common.util.constain.DicTypeConstant;
import com.cbwl.eoas.common.web.Result;



/**
 * 
 * <p>[描述信息：注释]</p>
 *
 * @author 虞云波 - yuyunbo@3856.cc
 * @version 1.0 Created on 2017年10月12日 下午13:29:23
 */
@Controller
@RequestMapping("/appoptionfeedback")
public class AppOptionFeedbackController {
	
	//业务层注解
	@Autowired
	private IAppOptionFeedbackService appOptionFeedbackService;
	
	//业务层注解
	@Autowired
	private IDictDetailService dictDetailService;
	
	
	
	/**
	 * <p>初始化界面</p>
	 * 
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/initAppOptionFeedback")
	public String initAppOptionFeedbackPage(HttpServletRequest request) {
		
		DictDetailDTO detailBean = new DictDetailDTO();
		detailBean.setDictTypeNo(DicTypeConstant.aof_status);
		request.setAttribute("beanlist", dictDetailService.queryObjectList(detailBean));
		
		return "initAppOptionFeedback";
	}


	/**
	 * <p>初始化新增修改界面</p>
	 * 
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/initAddUpdateAppOptionFeedbackPage")
	public String initAddUpdateAppOptionFeedbackPage(HttpServletRequest request,AppOptionFeedbackDTO bean) {
		request.setAttribute("bean", bean);
		
		
		
		return "initAddUpdateAppOptionFeedbackPage";
	}
	

	/**
	 * <p>查询（分页）</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/queryAppOptionFeedbackPage")
	@ResponseBody
	public Object queryAppOptionFeedbackPage(AppOptionFeedbackDTO bean,PageRequest pageRequest) {
		Result result = new Result(Result.Status.OK, "查询成功", "200");
		result.setData(appOptionFeedbackService.queryPageList(bean, pageRequest));
		return result;
	}

	/**
	 * 
	 * <p>通过id查询主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/getAppOptionFeedbackById")
	@ResponseBody
	public Object getAppOptionFeedbackById(AppOptionFeedbackDTO bean) {
		return appOptionFeedbackService.getObjectById(bean);
	}

	/**
	 * 
	 * <p>保存主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/saveAppOptionFeedback")
	@ResponseBody
	public Object saveAppOptionFeedback(AppOptionFeedbackDTO bean) throws Exception {


		bean.setGmtCreate(new Date());
		bean.setCreater(SessionManager.getCurrentUser().getId());
	
		return appOptionFeedbackService.saveObject(bean);
	}

	/**
	 * 
	 * <p>更新主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/updateAppOptionFeedback")
	@ResponseBody
	public Object updateAppOptionFeedback(AppOptionFeedbackDTO bean) throws Exception {
		if(StringUtils.isEmpty(bean.getAofBackContext()) || StringUtils.isEmpty(bean.getAofKey())){
			new CustomException("CBWL-000006");
		}
		
		bean.setGmtModified(new Date());
		bean.setModifier(SessionManager.getCurrentUser().getId());
		bean.setAofStatus(DicDetailConstant.aof_status_2);
		
		return appOptionFeedbackService.updSendPushFeedBack(bean);
	}

	/**
	 * 
	 * <p>删除主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc 
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 * @throws Exception 
	 */
	@RequestMapping("/deleteAppOptionFeedback")
	@ResponseBody
	public Object deleteAppOptionFeedback(AppOptionFeedbackDTO bean) throws Exception {
		return appOptionFeedbackService.deleteObject(bean);
	}
}
